//
//  YZMSpreadViewController.m
//  YZMicroStock
//
//  Created by apple on 17/1/4.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "YZMSpreadViewController.h"
#import "YZMSpreadDetailView.h"
#import "YZMSpreadUserView.h"
#import "YZMSegmentViewFixed.h"
#import "YZMSegmentViewScroll.h"

@interface YZMSpreadViewController ()<YZMSegmentViewDelegate>
{
    YZMSpreadDetailView *spreadDetailView;
    YZMSpreadUserView *spreadUserView;
    
}
@property(nonatomic, strong) YZMSegmentViewScroll *segMentView;

@end

@implementation YZMSpreadViewController

- (instancetype)init{
    self = [super init];
    if (self) {
        self.hidesBottomBarWhenPushed=YES;
        self.view.backgroundColor = [YZMAppStyle appBackgroundColor];
        self.title = @"推广赚钱";
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self createObject];
    // Do any additional setup after loading the view.
}


-(void)viewWillAppear:(BOOL)animated{
    
    [spreadDetailView reloadLoginView];
}

- (void)showDetailViewPage{
    
    [self.segMentView clickAtIndex:0];
}

- (void)segmentView:(YZMSegmentView *)segmentView didScrollToIndexView:(NSInteger)index{
    
    if(index == 1){
        
        if (!YZMUserServiceInstance.currentUser) {
            
            __weak __typeof(&*self) weakSelf = self;
            
            [YZMUserService showLoginCtrlWithSourcePageName:@"AboutSpread" andAheadAction:^{
                
                [spreadUserView reloadData];
            } andBackAction:^{
                
                [weakSelf showDetailViewPage];
            }];
        }
    }
}

-(void)createObject{
    
    self.segMentView = [YZMSegmentViewScroll new];
    [self.view addSubview:self.segMentView];
    self.segMentView.delegate = self;
    [self.segMentView mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.left.right.top.equalTo(self.view);
        make.height.mas_equalTo(ScreenHeight-64);
    }];
    
    spreadDetailView=[[YZMSpreadDetailView alloc]initWithFrame:self.view.frame];
    spreadUserView=[[YZMSpreadUserView alloc]initWithFrame:self.view.frame];
    
    self.segMentView.titleArray = @[@"推广详情",@"我的用户"];
    self.segMentView.viewArray=@[spreadDetailView,spreadUserView];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
